package chou;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Demo {
    public static void main(String[] args) throws InterruptedException {
        ArrayList<Integer> list = new ArrayList<>();
        int[] prizes = {10, 5, 20, 100, 500, 200, 800, 2, 80, 300, 700};
        for(int  prize : prizes){
            list.add(prize);
        }
        HashMap<String,ArrayList<Integer>> recordMap = new HashMap<>();
        MyThread[] threads = new MyThread[10];
        for(int i=0;i<10;i++){
            threads[i] = new MyThread(list,recordMap);
            threads[i].setName("抽奖箱"+(i+1));
            threads[i].start();
        }
        String maxBox = null;
        int maxPrize = 0;

        for (MyThread t : threads) {
            t.join();
        }

        for (Map.Entry<String, ArrayList<Integer>> entry : recordMap.entrySet()) {
            String box = entry.getKey();
            ArrayList<Integer> list1 = entry.getValue();
            int sum = 0;
            for (int val : list1) {
                sum += val;
                if (val > maxPrize) {
                    maxPrize = val;
                    maxBox = box;
                }
            }
            System.out.println(box + " 抽到了: " + list1 + "，总计：" + sum + "元");
        }

        System.out.println("最大奖项是：" + maxPrize + "元，由 " + maxBox + " 抽中");
    }
    }
